package com.lhbjl;

/**
 * @version 0.0.1
 * @author:liuhui
 * @date 2020/5/9
 */
public class TwoSum {

    public int[] twoSum(int[] nums, int target) {
        int[] result = new int[2];
        for (int x = 0; x < nums.length ; x ++){
            for (int y = x + 1; y < nums.length ; y ++){
                if(nums[x] + nums[y] == target){
                    result[0] = x;
                    result[1] = y;
                }
            }
        }
        return result;
    }

    public static void main(String[] args) {
//        System.out.println(new TwoSum().towSum1(new int[]{2049,3,4,1},2050));
        System.out.println(2052&4096);
    }

    public int[] towSum1(int[] nums, int target){
        int volume =4096; //100000000000
        int bitMode = volume-1;//011111111111
        int [] result =new int[volume];

        for (int i=0;i<nums.length;i++){
            int c = (target - nums[i]) & bitMode;
            if (result[c]!=0){
                return new int[]{result[c]-1,i};
            }
            result[nums[i] & bitMode]=i+1;
        }
        return null;
    }
}
